import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);


export default ()=>{
    let store = new Vuex.Store({
        state:{
            username:'hl'
        },
        mutations:{
            changeName(state){
                state.username = 'zx'
            }
        },
        actions:{
            changeName({commit}){
                return new Promise((res,rej)=>{
                    setTimeout(() => {
                        commit('changeName');
                        res();
                    }, 1000);
                })
            }
        }
    })
    // 在浏览器运行代码
if(typeof window !== 'undefined' && window.__INITIAL_STATE__){
    store.replaceState(window.__INITIAL_STATE__);
}
    return store 
}